package cn.jit.ssm.web.controller.demo;

import cn.jit.ssm.support.JSONReturn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: Cecurio
 * @create: 2017-12-07 10:05
 **/
@Controller
@RequestMapping(value = "/demo1")
public class DemoController1 {
    final Logger logger = LoggerFactory.getLogger(DemoController1.class);

    /**
     * SpringMVC获取cookie的Demo
     * @param cookie
     * @return
     */
    @RequestMapping("/displayHeaderInfo")
    @ResponseBody
    public JSONReturn displayHeaderInfo(@CookieValue("JSESSIONID") String cookie) {
        logger.info(cookie);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("JSESSIONID",cookie);
        return JSONReturn.build(false, map);
    }

    /**
     * 异常处理，500异常，如果加了500异常处理界面，就使用该界面；
     * 如果没有，则使用tomcat等容器的500界面，打印出详细的异常信息；
     * 线上运行环境，应该有专门的异常处理界面
     * @return
     */
    @RequestMapping(value = "/exception")
    @ResponseBody
    public JSONReturn byZero() {
        int i = 1 / 0;
        return JSONReturn.build(false, "byZero 异常");
    }
}
